package customerEnter.Frame.JDBCDao.daoFrame;

import java.util.List;

import org.springframework.stereotype.Service;

import customerEnter.Frame.Error.FramErrorProcessing;
import customerEnter.Frame.JDBCDao.Interface.DaoFrameDMLBaseInterfaces;
import customerEnter.Frame.JDBCDao.Interface.ParametersResultInterface;

@SuppressWarnings({ "rawtypes", "hiding" })
@Service("dMLParameterSetting")
public class DMLParameterSettingImpl<T, K> extends DaoFrameDMLTransImpl<T, K>
		implements DaoFrameDMLBaseInterfaces<T, K> {

	public DMLParameterSettingImpl() {

	}

	/**
	 * 查找這個表裡面所有數據返回 bean的所有屬性 有缓存
	 * 
	 * @throws FramErrorProcessing
	 */
	public <T> List<K> findAll(String tableName, Class<K> class1) {
		return ExecuteConditionResultObject(
				dmlParameterSettingInterface.findQueryList("*", tableName, null, class1, false, false));
	}

	/**
	 * 
	 * 根據id查找單個值 有缓存
	 */
	public K findId(Integer id, String tableName, Class<K> class1) {
		return ExecuteConditionResultObject(
				dmlParameterSettingInterface.findQueryBean(null, tableName, " where id=" + id, class1, true));
	}

	/**
	 * 根據條件查找 有缓存
	 */
	public List<K> findSeleList(String where, String tableName, Class<K> class1) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryList(null, tableName,
				SqlDataBaseController.getWhere() + where, class1, false, true));
	}

	/**
	 * 根據條件查找（填寫表名） 无缓存
	 */
	public <K> List<K> findSeleList(String Front, String ClassName, String where, Class<K> class1) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryList(Front, ClassName,
				SqlDataBaseController.getWhere() + where, class1, false, false));
	}

	/**
	 * 根據條件查找數據數量 无缓存
	 */
	public List<K> findSeleCont(String Front, String ClassName, String where, Class<K> class1) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryList(Front, ClassName,
				SqlDataBaseController.getWhere() + where, class1, false, false));
	}

	/**
	 * 根據條件查找（可查找數據傳輸類型 單次查詢 有緩存） //要記得在條件 參數 添加and。。
	 */
	public <A> List<A> findSelecClasses(String Front, String ClassName, String where, Class<A> Class) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryList(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, false, true));
	}

	/**
	 * 根據條件查找（可查找數據傳輸類型 可多重查詢 有緩存） 沒有 where 1=1
	 */
	public <T> List<T> findSelecJoinOnTable(String Front, String ClassName, String where, Class<T> Class) {
		return ExecuteConditionResultObject(
				dmlParameterSettingInterface.findQueryList(Front, ClassName, where, Class, false, true));
	}

	/**
	 * 根據條件查找（可查找數據傳輸類型 單次查詢 無緩存）
	 */
	public <T> List<T> findSelecNoEachClasses(String Front, String ClassName, String where, Class<T> Class) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryList(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, false, false));
	}

	/**
	 * 根據條件查找（可查找數據傳輸類型 單次查詢 無緩存 返回單個對象）
	 * 
	 * @param <OBj>
	 *            傳入的類型參數
	 */
	public <Other> Other findSelecNoEachSingle(String Front, String ClassName, String where, Class<Other> Class) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryBean(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, false));
	}

	/**
	 * 查詢數據 沒有緩存
	 */
	public <Transmission> List<Transmission> findTransmissionData(String Front, String ClassName, String where,
			Class<Transmission> Class) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryList(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, false, false));
	}

	/**
	 * 查詢統計數據
	 */
	public <T> T findCountData(String Front, String ClassName, String where) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryInteger(Front, ClassName,
				SqlDataBaseController.getWhere() + where));
	}

	/**
	 * 添加 映射表 根據對象的屬性名和數據庫裡面的字段想對應
	 */

	public <T> T saveTable(String Table, Object MappingObject) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.InsterObject(Table, MappingObject));
	}

	/**
	 * 添加 映射表 根據對象的屬性名和數據庫裡面的字段想對應
	 */
	public <T> T saveTableReturnId(String Table, Object MappingObject) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.InsterObject(Table, MappingObject, true));
	}

	/**
	 * 修改數據庫 映射對象到數據庫
	 */

	public <T> T UpdateTable(String TableName, Object MappingObject, String where) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.updateTable(TableName, MappingObject, where));
	}

	/**
	 * 分頁查詢數據 有緩存 自动排序 只需要写排序的字段名
	 */
	public <Transmission> List<Transmission> findPagingTransmissionCacheData(String Front, String ClassName,
			String where, int size, int page, String order, String descOrAsc, Class<Transmission> Class) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryPage(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, false, true, size, page, order, descOrAsc));
	}

	/**
	 * 分頁查詢數據 沒有緩存 自动排序 只需要写排序的字段名 根據時間排序
	 */
	public <Transmission> List<Transmission> findPagingTransmissionData(String Front, String ClassName, String where,
			int size, int page, String order, String descOrAsc, Class<Transmission> Class) {

		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryPage(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, false, false, size, page, order, descOrAsc));
	}

	/**
	 * 分頁查詢數據 有緩存 自动排序 只需要写排序的字段名 根據時間排序（使用此類）
	 */
	public <Transmission> List<Transmission> findPagingTransmissionCacheData(String Front, String ClassName,
			String where, int size, int page, String order, String descOrAsc, int position, Class<Transmission> Class) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryPageTime(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, false, true, size, page, order, descOrAsc, position));
	}

	/**
	 * 分頁查詢數據 沒有緩存 自动排序 只需要写排序的字段名（使用此類）
	 */
	public <Transmission> List<Transmission> findPagingTransmissionData(String Front, String ClassName, String where,
			int size, int page, String order, String descOrAsc, int position, Class<Transmission> Class) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryPageTime(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, false, false, size, page, order, descOrAsc, position));

	}

	/**
	 * 分頁查詢數據 有緩存,自动排序 只需要写排序的字段名
	 */
	public ParametersResultInterface findPagingParametersResultCacheData(String Front, String ClassName, String where,
			int size, int page, String order, String descOrAsc, Class<?> Class) {
		return findConditionQueryPageResult(dmlParameterSettingInterface.findQueryPage(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, true, true, size, page, order, descOrAsc));
	}

	/**
	 * 分頁查詢數據 沒有緩存 自动排序 只需要写排序的字段名
	 */
	public ParametersResultInterface findPagingParametersResultData(String Front, String ClassName, String where,
			int size, int page, String order, String descOrAsc, Class<?> Class) {
		return findConditionQueryPageResult(dmlParameterSettingInterface.findQueryPage(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, true, false, size, page, order, descOrAsc));
	}

	/**
	 * 批量增加數據
	 * 
	 * @param <Transmission>
	 */

	public <Transmission> Object InsertBatch(String TableName, List<Transmission> t, Class<Transmission> class1) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.InsertBatch(TableName, t, class1));
	}

	/**
	 * 查詢單個
	 * 
	 */

	public <DaoAutomatic> DaoAutomatic queryDMLId(int id, String tableName, Class<DaoAutomatic> Class) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryBean("*", tableName,
				SqlDataBaseController.getWhere() + " and id=" + id, Class, false));
	}

	/**
	 * 查詢單個對象有緩存
	 * 
	 * 
	 */
	public <DaoAutomatic> DaoAutomatic querySingleDate(String Front, String ClassName, String where,
			Class<DaoAutomatic> Class) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryBean(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, true));
	}

	/**
	 * 根據id刪除數據
	 */

	public Integer deleteObject(String TableName, int id) {
		return ExecuteConditionResultObject(
				dmlParameterSettingInterface.delete(TableName, SqlDataBaseController.getWhere() + " and id=" + id));
	}

	/**
	 * 根據條件刪除
	 */
	public Integer deleteObject(String TableName, String where) {
		return ExecuteConditionResultObject(
				dmlParameterSettingInterface.delete(TableName, SqlDataBaseController.getWhere() + where));
	}

	/**
	 * where 只能寫 and id=?
	 */
	public <Transmission> Transmission UpdateTableBatch(String TableName, List<?> t, String where) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.updateTableBatch(TableName, t, where));
	}

	/**
	 * -----------------------------------下面可以填入佔位符----------------------------
	 * --
	 * 
	 */
	@Override
	public <T> T savePreparedStatementReturnId(String Table, Object[] objects) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.savePreparedStatementReturnId(Table, objects));
	}

	@Override
	public <T> T UpdatePreparedStatement(String TableName, String where, Object[] objects) {
		return ExecuteConditionResultObject(
				dmlParameterSettingInterface.UpdatePreparedStatement(TableName, where, objects));
	}

	@Override
	public <T> T savePreparedStatementBatch(String Table, List<Object[]> objects) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.savePreparedStatementBatch(Table, objects));
	}

	@Override
	public <Transmission> Transmission UpdatePreparedStatementBatch(String TableName, String where,
			List<Object[]> objects) {
		return ExecuteConditionResultObject(
				dmlParameterSettingInterface.UpdatePreparedStatementBatch(TableName, where, objects));
	}

	@Override
	public <DaoAutomatic> DaoAutomatic querySingleMap(String Front, String ClassName, String where) {
		// TODO Auto-generated method stub
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryMap(Front, ClassName,
				SqlDataBaseController.getWhere() + where, false));
	}

	@Override
	public <DaoAutomatic> DaoAutomatic querySingleListObjects(String Front, String ClassName, String where) {
		// TODO Auto-generated method stub
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryListObjects(Front, ClassName,
				SqlDataBaseController.getWhere() + where, false));
	}

	@Override
	public <DaoAutomatic> DaoAutomatic querySingleListMap(String Front, String ClassName, String where) {
		// TODO Auto-generated method stub
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryListMap(Front, ClassName,
				SqlDataBaseController.getWhere() + where, false));
	}

	@Override
	public <DaoAutomatic> DaoAutomatic querySingleString(String Front, String ClassName, String where) {
		// TODO Auto-generated method stub
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryString(Front, ClassName,
				SqlDataBaseController.getWhere() + where, false));
	}

	@Override
	public <DaoAutomatic> List<DaoAutomatic> querySingleListPageMap(String Front, String ClassName, String where,
			int size, int page, String order, String descOrAsc, int position) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryListPageMap(Front, ClassName,
				SqlDataBaseController.getWhere() + where, null, false, false, size, page, order, descOrAsc, position));
	}

	@Override
	public <T> List<T> findSelecNoEachOneOrMay(String Front, String ClassName, String where, Class<T> Class) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryOneOrMayList(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, false, false));
	}

	@Override
	public <T> List<T> findSelecEachOneOrMay(String Front, String ClassName, String where, Class<T> Class) {
		return ExecuteConditionResultObject(dmlParameterSettingInterface.findQueryOneOrMayList(Front, ClassName,
				SqlDataBaseController.getWhere() + where, Class, false, true));
	}
}
